<template>
  <div>
    <avue-crud
      :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      ref="crud"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @sort-change="sortChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button type="primary" size="small" @click.stop="addWhite" >添加商户白名单</el-button >
      </template>

      <template slot-scope="{}" slot="serviceNoSearch">
        <select-page ref="searchSerSelect" label="serviceName" value="serviceNo" :select.sync="search.serviceNo" :url="website.searchLink.serviceUrl" placeholder-text="服务商" filter-key="searchParam"></select-page>
      </template>

      <template slot-scope="{}" slot="rpiNoSearch">
        <select-page ref="searchRpiSelect" label="rpiName" value="rpiNo" :select.sync="search.rpiNo" :url="website.searchLink.merchantUrl" placeholder-text="商户" filter-key="searchParam" @update:select="updateRpiChange"></select-page>
      </template>

    </avue-crud>
    <el-dialog
      :title="dialogModel.text"
      top="3%"
      :width="screenWidth>1920?'30%':(screenWidth<=1920 && screenWidth>1500)?'30%':'90%'"
      append-to-body
      :close-on-click-modal="false"
      :visible.sync="dialogModel.visible"
      v-if="dialogModel.visible"
      :before-close="handleClose"
    >
      <div class="z_flex"> 
        <span style="min-width:60px;">商户:</span>
        <!-- @update:select="updateRpiChange" -->
        <select-page style="width:100% !important;" ref="searchRpiSelect" label="rpiName" value="rpiNo" :select.sync="modelForm.rpiNo" :url="website.searchLink.merchantUrl" placeholder-text="商户" filter-key="searchParam"></select-page>
      </div>
      <div slot="footer">
        <el-button size="small" type="primary" @click="modelSubmit">{{dialogModel.subText}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getList } from "@/api/rb-oem/posinfo/pos_info";
import selectPage from "@/components/select-page/select-page";
export default {
components: {
  selectPage
},
data() {
  const serviceTypeValidate = (rule, value, callback) => {
    if (value === "") {
      callback(new Error("请输入参数"));
    } else if (isNaN(value)) {
      callback(new Error("请输入数字型参数"));
    } else {
      callback();
    }
  };
  const validatePhone = (rule, value, callback) => {
    if (value === "") {
      callback(new Error("请输入手机号"));
    } else if (!isMobile(value)) {
      callback(new Error("手机号码不正确！"));
    } else {
      callback();
    }
  };
  return {
    screenWidth: document.documentElement.clientWidth,
    loading: true,
    query: {},
    search: {},
    dialogVisible: false,
    page: {
      pageSize: 10,
      currentPage: 1,
      serviceKind: 1,
      total: 0
    },
    option: {
      height: "calc(50vh - 50px)",
      calcHeight: 30,
      tip: false,
      border: true,
      index: true,
      viewBtn: false,
      addBtn: false,
      editBtn: false,
      delBtn: true,
      selection: false,
      indexLabel:'序号',
      menuWidth: 100,
      searchMenuSpan: 24,
      searchLabelWidth: 120, //搜索框标题宽度
      // searchIcon:true,
      column: [
          {
            label: "服务商",
            prop: "serNo",
            type: "select",
            display: false,
            search: true,
            hide: true,
            rules: [
              {
                required: true,
                message: "请选择服务商",
                trigger: "blur",
              }
            ],
            overHidden: true,
            minWidth: 150
          },
          {
            label: '',
            prop: 'isAllSer',
            type: 'select',
            multiple: false,
            dataType: "string",
            showColumn: false,
            hide: true,
            search: true,
            searchType:"checkbox",
            searchSpan: 0,
            searchLabelWidth: '0',
            dicData: [{
              label:'包含下级',
              value: 1
            }]
          },
          {
            label: "商户编号",
            searchLabel: "商户",
            prop: "rpiNo",
            type: 'select',
            minWidth: 140,
            display: false,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入商户号",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: "门头名称",
            prop: "rpiName",
            type: "input",
            minWidth: 200,
            rules: [
              {
                required: true,
                message: "请输入门头名称",
                trigger: "blur",
              },
            ]
          },
          {
            label: "注册名称",
            prop: "registeredName",
            type: "input",
            minWidth: 200,
            rules: [
              {
                required: true,
                message: "请输入注册名称",
                trigger: "blur",
              },
            ]
          },
          {
            label: "商户简称",
            prop: "userShortName",
            type: "input",
            minWidth: 200,
            search: true,
            rules: [
              {
                required: true,
                message: "请输入商户简称",
                trigger: "blur",
              },
            ]
          },
          {
            label: "所属服务商",
            minWidth: 200,
            prop: "serName",
            slot: true,
            display: false,
            overHidden: true,
          },
          {
            label: "创建日期",
            prop: "createTime",
            minWidth: 150,
            span: 24,
            addDisplay: false,
            editDisplay: false,
          },
          {
            label: "创建开始日期",
            prop: "beginTime",
            // type: "datetime",
            // format:'yyyy-MM-dd HH:mm:ss',
            // valueFormat:'yyyy-MM-dd HH:mm:ss',
            // defaultTime:"00:00:00",
            search: true,
            hide: true,
            display: false
          },
          {
            label: "创建结束日期",
            prop: "endTime",
            // type: "datetime",
            // format:'yyyy-MM-dd HH:mm:ss',
            // valueFormat:'yyyy-MM-dd HH:mm:ss',
            // defaultTime:"23:59:59",
            search: true,
            hide: true,
            display: false
          }
      ]
    },
    data: [],
    dialogModel:{
      type:'',
      text:'',
      visible:false,
      subText:''
    },
    checked:false,
    modelForm:{
      rpiNo:''
    }
  };
},
computed: {},
created(){
  this.$refs.crud.doLayout();
},
methods: {
  handleClose(done) {
    this.initDialogModel();
    done()
  },
  initDialogModel(){
    this.dialogModel={
      type:'',
      text:'',
      visible:false,
      subText:''
    }
    this.modelForm={
      serviceNo:'',
      isSelectChild:0
    }
  },
  addWhite(){
    this.dialogModel={
      type:'add',
      text:'添加白名单',
      visible:true,
      subText:'确认添加'
    }
  },
  rowDel(row) {
    this.$confirm("确定将选择数据删除?", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        // return remove(row.id);
      })
      .then(() => {
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!",
        });
      });
  },
  onLoad(page, params = {}) {
    this.loading = true;
    getList(
      page.currentPage,
      page.pageSize,
      page.serviceKind,
      Object.assign(params, this.query)
    ).then((res) => {
      const data = res.data.data;
      this.page.total = data.total;
      this.data = data.records;
      this.loading = false;
    });
  },
  sortChange(val) {
    if (val.order == "ascending") {
      //正序
      this.query.ascs = val.prop;
      this.query.descs = "";
    } else {
      //倒序
      this.query.descs = val.prop;
      this.query.ascs = "";
    }
    this.refreshChange();
  },
  searchReset() {
    this.query = {};
    this.onLoad(this.page);
  },
  searchChange(params, done) {
    this.query = params;
    this.page.currentPage = 1;
    this.onLoad(this.page, params);
    done();
  },
  currentChange(currentPage) {
    this.page.currentPage = currentPage;
  },
  sizeChange(pageSize) {
    this.page.pageSize = pageSize;
  },
  refreshChange() {
    this.onLoad(this.page, this.query);
  }
}
};
</script>

<style lang="scss" scoped>
.z_flex{
display: flex !important;
align-items: center;
}

/deep/ .el-select--small{
  width: 100% !important;
}
</style>
